<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page isELIgnored="false"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>翼飞新零售商户平台</title>
    <script type="text/javascript" src="<%=basePath%>js/commons/common_edit.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>css/jquery-ui.css">
    <link href="<%=basePath%>images/ico.ico" type="image/x-icon" rel="icon">
    <link href="<%=basePath%>css/public.css" rel="stylesheet" />
    <link href="<%=basePath%>css/login.css" rel="stylesheet" />
    <script type="text/javascript">
	$(document).ready(function(){
		//如果不是顶层，则跳转到顶层
		 if (window != top){
			top.location.href = location.href;
		}
	}); 
    function _loginsubmit(){
    	if($("#UserName").val()==""||$("#UserPwd").val()==""){
    		$("#error4").show();
    		$("#error1").hide();
    		$("#error2").hide();
    		$("#error3").hide();
    	}else{
	   		if(_validateUserName()){
   				if(_validateUserPwd()){
   					if(_validateUserStatus()){
   						document.srcForm.action="<%=path%>/loginAction/Login.action";
   						document.srcForm.submit();
   					}
   				}
	   		}
    	}
    }
    //该用户不存在
	 function _validateUserName(){
		var flag = false;
	 	$.ajax({  
				    type: "post",  
				    async: false,
				    url: "<%=basePath%>/userAjax/validateUser.action",  
				    data: {                     //要传递的数据
					        "UserName": function() {
					            return $("#UserName").val();
					        }
						 },  
				    success: function(data){ 
				    	if(data=='true'){
						    $("#error1").show();
							$("#error4").hide();
				    		$("#error2").hide();
				    		$("#error3").hide();
						    flag = false;
				    	}else{
						    $("#error1").hide();
				    		flag = true;
				    	}
				    }
			});
			return flag;
	 }
	 //密码错误
	 function _validateUserPwd(){
		var flag = false;
	 	$.ajax({  
				    type: "post",  
				    async: false,
				    url: "<%=basePath%>/userAjax/validateUserPwd.action",  
				    data: {
					        "UserPwd": function() {
					            return $("#UserPwd").val();
					        },
					        "UserName": function() {
					            return $("#UserName").val();
					        }
					    },
				    success: function(data){ 
				    	if(data=='false'){
						    $("#error2").show();
							$("#error1").hide();
				    		$("#error4").hide();
				    		$("#error3").hide();
						    flag = false;
				    	}else{
						    $("#error2").hide();
				    		flag = true;
				    	}
				    }
					
			});
			return flag;
	 }
	 //用户是否停用
	 function _validateUserStatus(){
		var flag = false;
	 	$.ajax({  
				    type: "post",  
				    async: false,
				    url: "<%=basePath%>/userAjax/validateUserStatus.action",  
				    data: {                     //要传递的数据
					        "UserPwd": function() {
					            return $("#UserPwd").val();
					        },
					        "UserName": function() {
					            return $("#UserName").val();
					        }
					    },
				    success: function(data){ 
				    	if(data=='false'){
						    $("#error3").show();
							$("#error1").hide();
				    		$("#error2").hide();
				    		$("#error4").hide();
						    flag = false;
				    	}else{
						    $("#error3").hide();
				    		flag = true;
				    	}
				    }
			});
			return flag;
	 }
	 
	 function keyLogin(){  
	   	if (event.keyCode==13)   //回车键的键值为13  
	   	//document.getElementById("_submit").click(); //调用登录按钮的登录事件  
	   	_loginsubmit();
	} 
    </script>
        <style type="text/css">
    	.error_txt{
    		display: none;
    		opacity: 0.8;
    		color:red;
    	}
    
    </style>
</head>

<body onkeydown="keyLogin()">
<form action="" method="post" name="srcForm" id="srcForm" >
    <!-- 登录表单开始 -->
    <div class="loginWrap mb50">
        <div class="w">
            <div class="loginInner">
           		<input class="userName" name="userInfo.UserName" id="UserName" placeholder="用户名/用户ID" type="text" onkeypress="_validate()">
            	<input class="passWord mb20" name="userInfo.UserPwd" id="UserPwd" type="password" placeholder="请输入密码" onkeypress="_validate()">
            	 <p class="error_txt" id="error1">该用户不存在</p>
            	 <p class="error_txt" id="error2">密码错误</p>
           		 <p class="error_txt" id="error3">该用户已被禁用</p>
           		 <p class="error_txt" id="error4">用户名或密码不能为空</p>
                <button class="btn_login mt20" name="_submit" id="_submit" onclick="_loginsubmit();return false;">登录系统</button>
            </div>
        </div>
    </div>
    <!-- 登录表单结束 -->
</form>
</body>
</html>

